package geowiki.threads;

import java.util.List;

import geowiki.data.Link;
import geowiki.data.YQLLinkExtractor;
import geowiki.data.YQLQuery;
import geowiki.utils.WikipediaUtils;
import processing.core.PApplet;

public class PlacesExtractionThreadTestApp extends PApplet {

	List<Link> links;

	public void setup() {
		size(800, 600);
		smooth();

		links = loadLinks("Frank_Brettschneider");
		println("Found " + links.size() + " links.");
		for (int i = 0; i < links.size(); i++) {
			PlacesExtractionThread pet = new PlacesExtractionThread(this, links.get(i));
			pet.start();
		}
	}

	public void draw() {
		background(250);
		
		if (links != null) {
			for (int i = 0; i < links.size(); i++) {
				Link link = links.get(i);
				for (int j = 0; j < link.storedPlaceMarkers.size(); j++) {
					link.storedPlaceMarkers.get(j).display();
				}
			}
		}
	}

	public List<Link> loadLinks(String wikipediaArticleName) {
		YQLLinkExtractor linkExtractor = new YQLLinkExtractor(this);
		String wikipediaURL = WikipediaUtils.getWikipediaArticleURL(wikipediaArticleName);
		String restURL = YQLQuery.getAllLinksFromWebpage(wikipediaURL);
		List<Link> alllinks = linkExtractor.getLinks(restURL);
		return alllinks;

	}
}
